package host.skiree.nettydemo.client.service.impl;

import host.skiree.nettydemo.client.handler.DemoClientHandler;
import host.skiree.nettydemo.client.service.MessageClientHandler;
import host.skiree.nettydemo.message.LoginResponseMessage;
import host.skiree.nettydemo.message.Message;
import io.netty.channel.ChannelHandlerContext;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author anorak
 */
public class Login implements MessageClientHandler {

    @Override
    public void handleMessage(ChannelHandlerContext ctx, Message message) {
        LoginResponseMessage loginMessage = (LoginResponseMessage) message;
        // 打印返回的结果
        System.out.println(loginMessage.getReason());
        if (loginMessage.isSuccess()){
            DemoClientHandler.LOGIN.set(true);
        }
        // 锁减1,释放
        DemoClientHandler.WAIT_FOR_LOGIN.countDown();
    }

}
